package com.miloyu.modelnet.response

import android.content.Context
import android.graphics.drawable.Drawable
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import com.example.mvvm.until.LogUtils
import com.example.mvvm.until.SPUtils
import com.sx.micowell.framework.app.SPKey

/**
 * @Description 根据文件名字找资源
 * @Author 梁浩文
 * @Date 2021/8/18 9:28
 */

fun String.getUrl() = SPUtils.getInstance().getString(SPKey.SP_IMAGE_PREFIX) + this

fun Context.getResId(packName: String, resName: String) :Int=
    resources.getIdentifier(resName, packName, getPackageName())

fun Context.getResDrawable(resId: Int): Drawable =
    ContextCompat.getDrawable(this, resId) as Drawable

fun Context.getResDrawable(resName: String, packName: String): Drawable =
    ContextCompat.getDrawable(this,this.getResId(resName, packName)) as Drawable

fun String.log()=LogUtils.i("MICOWELL${this}")
fun Int.log()=LogUtils.i("MICOWELL${this}")
fun Float.log()=LogUtils.i("MICOWELL${this}")
fun Double.log()=LogUtils.i("MICOWELL${this}")

fun FragmentManager.addFragment(fragment: Fragment, frameId: Int){
    this.inTransaction { add(frameId, fragment) }
}


fun FragmentManager.replaceFragment(fragment: Fragment, frameId: Int) {
    this.inTransaction{replace(frameId, fragment)}
}

inline fun FragmentManager.inTransaction(func: FragmentTransaction.() -> FragmentTransaction) {
    beginTransaction().func().commit()
}
